import java.math.BigInteger;

public class Text {
    public static void main1(String[] args) {
        int i = 1;
        int sum = i;
        for (int j = 2; j <= 100; j++) {
            i+=j;
            sum += i;
        }

        System.out.println(QurNum(3));
    }
    public static int QurNum(int num) {
        int max = num;
        int sum = 0;
        for (int i = 0; i < 100; i++) {
            int tmp = num;

            while(tmp != 0){
                int j = (tmp%10) * (tmp%10);
                tmp /= 10;
                sum += j;
            }
            if(sum > max){
                max = sum;
            }
            num = sum;
            sum = 0;
        }
        return max;
    }
    static int[] a = {1,2,3,4,5,6,7,8,9};
    static int count =0;
    public static boolean check() {
        int x = a[3]*100 + a[4]*10 + a[5];
        int y = a[6]*100 + a[7]*10 + a[8];
        if(a[0] + ((a[1]*y)+(a[2]*x)) / (a[2]*y) == 10 &&
                ((a[1]*y)+(a[2]*x)) % (a[2]*y) ==0 ) {
            return true;
        }
        return false;
    }
    public static void f(int k) {
        if(k == 9){
            if(check()) {
                count++;
            }
        }

        for (int i = k; i < 9; i++) {
            {
                int t = a[i];
                a[i] = a[k];
                a[k] = t;
            }

            f(k+1);

            {
                int t = a[i];
                a[i] = a[k];
                a[k] = t;
            }

        }
    }

    public static void main2(String[] args) {
        f(0);
        System.out.println(count);
    }

}
